package com.tangxz.comparison.test;


import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * Description:
 * User: Administrator
 * Date: 2025/3/2 21:32
 */

public class MethodUtils {

    public static Object invokeBMethod(Object target, Object[] args) throws Exception {
        Class<?> targetClass = target.getClass();
        // 假设B方法名称是methodB，实际可根据需要修改
        Method methodB = targetClass.getMethod("methodB", getParameterTypes(args));
        return methodB.invoke(target, args);
    }

    private static Class<?>[] getParameterTypes(Object[] args) {
        return Arrays.stream(args)
                .map(Object::getClass)
                .toArray(Class<?>[]::new);
    }
}